package io.github.harmonly.mapper;

import io.github.harmonly.entity.association.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AssociationMapper {

    /**
     * Association
     */
    @Select("select * from association")
    List<Association> getAssociations();

    @Select("select * from association where name like '%' #{name} '%'")
    List<Association> getAssociationsByName(String name);

    @Select("select * from association where tag like '%' #{tag} '%'")
    List<Association> getAssociationsByTag(String tag);

    @Select("select * from association where aid = #{aid}")
    Association getAssociation(int aid);

    @Insert("insert into association(uid, name, tag, `desc`, face, date, money) values (#{uid}, #{name}, #{tag}, #{desc}, #{face}, #{date}, #{money})")
    int addAssociation(Association association);

    @Delete("delete association from association where aid = #{aid}")
    int deleteAssociation(int aid);

    @Update("update association set uid = #{uid}, name = #{name}, tag = #{tag}, `desc` = #{desc}, face = #{face}, date = #{date}, money = #{money} where aid = #{aid}")
    int editAssociation(Association association);

    /**
     * Association Honor
     */
    @Select("select * from association_honor")
    List<AssociationHonor> getHonors();

    @Select("select * from association_honor where aid = #{aid}")
    List<AssociationHonor> getHonorsByAid(int aid);

    @Select("select * from association_honor where ahid = #{ahid}")
    AssociationHonor getHonor(int ahid);

    @Insert("insert into association_honor(aid, honor, time) values (#{aid}, #{honor}, #{time})")
    int addHonor(AssociationHonor honor);

    @Delete("delete association_honor from association_honor where ahid = #{ahid}")
    int deleteHonor(int ahid);

    @Update("update association_honor set aid = #{aid}, honor = #{honor}, time = #{time} where ahid = #{ahid}")
    int editHonor(AssociationHonor honor);
}
